package com.bbs.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *  数据库链接 关闭
 * @author caikc
 *
 */
public class DB {
	
	/**
     * 数据库连接
     * @return Connection
     */
    public static Connection getConnection(Connection conn){
    	try {
			Class.forName("com.mysql.jdbc.Driver");
			conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bbs", "root", "Oracle11");
			    
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn ;
    }
    
    /**
     *  关闭ResultSet PreparedStatement Connection
     * @return true成功关闭，false关闭失败
     * @throws SQLException 
     */
    public static boolean getClose(ResultSet rs, PreparedStatement pstm, Connection conn) throws SQLException{
    	if(rs != null) {
    		rs.close();
    	}
    	if(pstm != null) {
    		pstm.close();
    	}
    	if(conn != null) {
    		conn.close();
    	}
    	return true;
    }

}
